/**
 * 
 */
package captor.modelsystem;

import java.util.Vector;

import captor.crosscuttingdomainsystem.crosscuttinginfo.DomainInfo;
import captor.domainsystem.DomainException;
import captor.domainsystem.DomainSystem;
import captor.lib.intl.MyIntl;

/**
 * @author Carlos
 *
 */
public abstract class CaptorDomain {
	
	protected Model model;
	protected DomainInfo crosscuttingDomainInfo;
	protected DomainSystem domainSystem;
	private String nameDomain;
	
	public CaptorDomain(){}
	
	public CaptorDomain(Model model, String nameDomain){
		this.model=model;
		this.nameDomain=nameDomain;
		domainSystem = new DomainSystem(model);
		
		try{
			crosscuttingDomainInfo = loadCrosscutingDomainInfo();
		}
		catch (DomainException e1){
			crosscuttingDomainInfo = null;
		}		
	}
		
	public CaptorDomain(Model model, String nameDomain, DomainInfo crosscuttingDomainInfo){
		this.model=model;
		this.nameDomain=nameDomain;
		this.crosscuttingDomainInfo = crosscuttingDomainInfo;
		domainSystem = new DomainSystem(model);
	}

	public String getNameDomain() {
		return nameDomain;
	}

	public void setNameDomain(String nameDomain) {
		this.nameDomain = nameDomain;
	};
	
	public void validateDomain() throws DomainException{
		
		DomainSystem ds = new DomainSystem(this.model);
		Vector vectorDomains = ds.getDomainNames();
		if (!vectorDomains.contains(nameDomain)){
			throw new DomainException(MyIntl.MSG127);
		}
		if (crosscuttingDomainInfo==null){
			throw new DomainException(MyIntl.MSG128);
		}
	}
	
	public DomainInfo loadCrosscutingDomainInfo() throws DomainException{
		
		try{									        
	        String path = domainSystem.getReadDomainInfoPath(this.nameDomain);
	        
	        return domainSystem.loadCrosscutingDomainInfo(path);
		}
		catch (Exception e1){
			throw new DomainException(MyIntl.MSG128);
		}		
	}
	
	public boolean isCrosscuttingDomain(){
		return false;
	}
	
	public abstract String getDomainDescription();
}